﻿
@inject NavigationManager NavigationManager
@inject IDataCacheService _dataCacheService
@inject IPopupService PopupService

@if (IsTitile)
{
    <MChip Class="@("rounded-lg ma-1"+ (IsTitile?" ms-0":""))" TextColor="@($"{(Color=="primary"?null:"white")}")"
           Color="@Color"
           Small>
        @Text
    </MChip>
}
else
{
    <MChip Class="@("rounded-lg ma-1"+ (IsTitile?" ms-0":""))"
               Color="@Color"
               Small
               TextColor="@Color"
               Outlined
                Href="@(EntryId>0?$"/entries/index/{EntryId}":null)"
               OnClick="OnClick">
            @if (IsShowExistTag && EntryId > 0)
            {
                <MIcon Color="@Color" Small Left>mdi-check-circle</MIcon>
            }
            @Text
        </MChip>

}


@if (string.IsNullOrWhiteSpace(ItemProp) == false && string.IsNullOrWhiteSpace(ItemType) == false)
{
    <div itemscope itemprop="@ItemProp" itemtype="@ItemType">
        <meta itemprop="name" content="@Text" />

    </div>

}


@code {
    [Parameter]
    public bool IsTitile { get; set; }
    [Parameter]
    public string Text { get; set; }
    [Parameter]
    public int EntryId { get; set; }
    [Parameter]
    public bool IsNotShowTip { get; set; }

    [Parameter]
    public bool IsShowExistTag { get; set; }
    [Parameter]
    public string ItemProp { get; set; }
    [Parameter]
    public string ItemType { get; set; }

    [Parameter]
    public string Color { get; set; } = "primary";




    public async Task OnClick()
    {
        if (EntryId > 0)
        {
            //NavigationManager.NavigateTo("/entries/index/" + EntryId);
        }
        else
        {
            if (IsNotShowTip == false && IsTitile == false)
            {
                if (IsShowExistTag)
                {
                    NavigationManager.NavigateTo("/entries/establishentry?Name=" + Text);
                }
                else
                {
                    await PopupService.ToastErrorAsync("该词条不存在", "你可以亲自创建“" + Text + "”哦~");

                }
            }
        }



    }
}
